﻿//-- =============================================
//-- Author:	    Unknown
//-- Create date:   Unknown
//-- Description:	Bank Properties And Validation Class [Get And Rewrite by Saghari, Farid]
//-- E-Mail:    	fredmcs@live.com
//-- Mobile:        0937-241-3499
//-- Last Update:   1390/01/10 13:10
//-- Important:     سلام دوستان. لطفا کسی این کلاس رو بدون هماهنگی کردن با من تغییر نده
//-- =============================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChequeManagement.BLL
    
{
    /// <summary>
    /// This Class contains number of Field,enum,properties,method and this class inheritance of BaseObject class
    /// </summary>
    /// <field>this field use in IsValid method for set parameter ApplicationInfo class</field>
    /// <properties>this properties contain set for receive value and contain get for return value that this properties Validation into IsValid method </properties>
    /// <method>this class contain IsValid method for Validation all properties</method>
    /// <enum>this enum contain BankID,BankName that use IsValid method on field "command" for set bankname </enum>
    public class BLLBank : BaseObject
    {
        /// <summary>
        /// This Field use in IsValid method on ApplicationInfo class for set parameter
        /// </summary>
        private string tableName = "Bank";
        /// <summary>
        /// This enum use in IsValid method for receive bankname and set bankname into field "command"
        /// </summary>
        public enum BankField
        {
            
            BankID,
            BankName
        }

        /// <summary>
        ///  This property contain set for receive value and contain get for return value this property have One to One Relation with bankName
        /// </summary>
        private int bankID;
        public int BankID
        {
            get
            {
                return (bankID);
            }
            set
            {
                bankID = value;
            }
        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value this property have One to One Relation with bankID
        /// </summary>
        private string bankName;
        public string BankName
        {
            get
            {
                return (bankName);
            }
            set
            {
                bankName = value;
            }
        }
        /// <summary>
        /// This method check "BankName" if BankName IsNullOrWhiteSpace or BankName Length further of 100,add Error
        /// If IsValid parameter not contains "BankName" create filed of string that name is "command" and vlaue is "BankName"
        /// If BankName contain chars 'ي','ك' Replace that with chars 'ی','ک'
        /// </summary>
        /// <param name="excepts" Type="String[]"></param>
        /// <returns>if all field is Valid return true else return false  </returns>

        public bool IsValid(params string[] excepts)
        {
            if (string.IsNullOrWhiteSpace(BankName))
                AddError("عنوان بانک خالی می باشد", null);
            else
            {
                if (BankName.Length > 100)
                    AddError("طول عنوان بانک نباید بیشتر از {0} کاراکتر باشد", 100);
                if (excepts.Contains("BankName") == false)
                {
                    string command = "[" + tableName + "].[" + BankField.BankName.ToString() + "] = N'" + BankName + "'";
                    Common.ApplicationInfo appInfo = new Common.ApplicationInfo(tableName);
                    System.Data.DataTable dataSource = new System.Data.DataTable();

                    object businessFactory = Activator.CreateInstance(Type.GetType(appInfo.BusinessLogicLayer));
                    Common.PDController.DoInvokeMember(businessFactory, new object[] { command, dataSource }, new string[] { "condition", "dataTable" });
                    if (dataSource != null && dataSource.Rows.Count > 0)
                        AddError("عنوان بانک <{0}> از قبل موجود میباشد", BankName);
                }
            }
            if (ErrorsCount > 0)
                return false;
            else
                return true;
        }
    }
}
